package dispatcher;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import business.Role;

import utils.MyBase64;

public class RejectCommentsGrid extends HttpServlet{

	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		HttpSession session = request.getSession(true);
		Object userID = session.getAttribute("userID");
		Object sessionUserRole = session.getAttribute("userRole");
		if(userID == null || userID.toString().trim().length() == 0)
		{
			response.sendRedirect("./login?option=" + MyBase64.encode(Login.NO_SESSION.getBytes()));
		}
		else
		{
			if(sessionUserRole.toString().equals(Role.ROLE_OPERATOR))
			{
				request.setAttribute("ATT_ENABLED_BTN", false);
			}
			else if(sessionUserRole.toString().equals(Role.ROLE_REVISOR) || sessionUserRole.toString().equals(Role.ROLE_COORD))
			{
				request.setAttribute("ATT_ENABLED_BTN", true);
			}
			RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/rejectCommentsGrid.jsp");
			dispatcher.forward(request, response);
		}
	}
}